<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk" %>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Отчет о работе склада</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/jquery.countdown.css">
    <style type="text/css">
        a{
            font-size: 1.3em;
        }

        .rich-table-subheadercell {
            white-space: normal;
        }

        .rich-table-cell{
            font-size: 1.1em;
            text-align: center;
        }
    </style>
</head>
<body>
<f:view>
<jsp:include page="menu.jsp"/>
<jsp:include page="status.jsp"/>
<h:form id="absenceReportForm">
    <h:panelGrid columns="6" cellpadding="0" cellspacing="0">
        <h:outputText value="Дата: " styleClass="b"/>
        <h:outputText value=" c "/>
        <rich:calendar value="#{StoreReportBean.beginDate}" locale="RU_ru"
                       datePattern="dd.MM.yyyy" style="width:80px;padding-left:4px;" id="calBegdate" required="true" requiredMessage="Необходимо выбрать временной период"/>
        <h:outputText value=" по "/>
        <rich:calendar value="#{StoreReportBean.endDate}" locale="RU_ru"
                       datePattern="dd.MM.yyyy" style="width:80px;padding-left:4px;" id="calEnddate" required="true" requiredMessage="Необходимо выбрать временной период"/>
        <a4j:commandButton value="Выбрать" action="#{StoreReportBean.reloadData}"
                           reRender="detailedOrderReport,form4" oncomplete="location.reload();">
            <f:setPropertyActionListener value="0" target="#{StoreReportBean.reportType}"/>
                           </a4j:commandButton>
    </h:panelGrid>

</h:form>

    <br />

    <h:form id="form4">
    <div style="display: table;">
        <h:outputText styleClass="b" style="font-size: 1.3em;" value="Вывезено со склада в м. куб"/>
        <h:outputText style="margin: 5px; font-size: 1.3em;" value="#{StoreReportBean.volumeOfExportedGoods}"/>
    </div>
    <br />
    <h3>
        Заказы
    </h3>
    <h:panelGrid columns="2" columnClasses="cgray,cwhite">
        <h:outputText value="Поступило" styleClass="b" style="font-size: 1.3em;"/>
        <h:outputText value="#{StoreReportBean.recivedOrdersCount}"  style="font-size: 1.3em;"/>
        <h:outputText value="Собрано вовремя" styleClass="b" style="font-size: 1.3em;"/>
        <a4j:commandLink value="#{StoreReportBean.prepareInTimeOrdersCount}" action="#{StoreReportBean.reloadData}" reRender="detailedOrderReport" oncomplete="location.reload();">
            <f:setPropertyActionListener value="1" target="#{StoreReportBean.reportType}"/>
        </a4j:commandLink>
        <h:outputText value="Не собрано вовремя" styleClass="b" style="font-size: 1.3em;"/>
        <a4j:commandLink value="#{StoreReportBean.notPrepareInTimeOrdersCount}" action="#{StoreReportBean.reloadData}" reRender="detailedOrderReport" oncomplete="location.reload();">
            <f:setPropertyActionListener value="2" target="#{StoreReportBean.reportType}"/>
        </a4j:commandLink>
        <h:outputText value="Доставлено вовремя" styleClass="b" style="font-size: 1.3em;"/>
        <a4j:commandLink value="#{StoreReportBean.deliveryInTimeOrdersCount}" action="#{StoreReportBean.reloadData}" reRender="detailedOrderReport" oncomplete="location.reload();">
            <f:setPropertyActionListener value="3" target="#{StoreReportBean.reportType}"/>
        </a4j:commandLink>
        <h:outputText value="Не доставлено вовремя" styleClass="b" style="font-size: 1.3em;"/>
        <a4j:commandLink value="#{StoreReportBean.notDeliveryInTimeOrdersCount}" action="#{StoreReportBean.reloadData}" reRender="detailedOrderReport" oncomplete="location.reload();">
            <f:setPropertyActionListener value="4" target="#{StoreReportBean.reportType}"/>
        </a4j:commandLink>
    </h:panelGrid>
</h:form>
    <br />
    <h:panelGroup id="detailedOrderReport" rendered="#{not empty StoreReportBean.orderList}">
        <h:form>
            <h2><h:outputText value="#{StoreReportBean.reportTypeAsString}"/></h2>
            <rich:dataTable value="#{StoreReportBean.orderList}" var="order" rowKeyVar="row" styleClass="full">

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="№"/>
                    </f:facet>
                    <h:outputText value="#{row + 1}. "/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Заказ"/>
                    </f:facet>
                    <h:outputText value="#{order.id}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Статус"/>
                    </f:facet>
                    <h:outputText value="#{order.orderStateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Клиент"/>
                    </f:facet>
                    <h:outputText value="#{order.client.companyName}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Менеджер"/>
                    </f:facet>
                    <h:outputText value="#{order.manager.fio}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Статус клиента"/>
                    </f:facet>
                    <h:outputText value="#{order.client.clientStateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата создания"/>
                    </f:facet>
                    <h:outputText value="#{order.creationDateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата сборки ожидаемая"/>
                    </f:facet>
                    <h:outputText value="#{order.expectedAssembyDate}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата сборки фактическая"/>
                    </f:facet>
                    <h:outputText value="#{order.orderStateIsOutput ? \"\" : order.assemblyDateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата отгрузки"/>
                    </f:facet>
                    <h:outputText value="#{order.deliveryDateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Дата отгрузки фактическая"/>
                    </f:facet>
                    <h:outputText value="#{order.factDeliveryDateAsString}"/>
                </rich:column>

                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Сумма"/>
                    </f:facet>
                    <h:outputText value="#{order.factSum == 0 ? order.sumAsString : order.factSumAsString}"/>
                </rich:column>

                <f:facet name="footer">
                        <rich:columnGroup>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column/>
                            <rich:column>
                                <h:outputText value="Итого: #{StoreReportBean.ordersSum}"/>
                            </rich:column>
                        </rich:columnGroup>
                </f:facet>
            </rich:dataTable>
        </h:form>
    </h:panelGroup>
</f:view>
</body>
